<?php

namespace yak\layui\widgets;

use yii\base\Widget;
use yii\helpers\Json;
use yii\web\View;

/**
 * Class LayuiView
 * @package yak\layui\widgets
 */
class LayuiView extends Widget
{
    /**
     * @var array
     */
    public $events = [];

    /**
     * @var array
     */
    public $options = [];

    public function run()
    {
        $this->options['_csrf'] = \Yii::$app->request->csrfToken;
        $js = 'layui.use([\'view\'], function () { layui.view.render(' . Json::encode($this->options) . ', ' . Json::encode($this->events) . ') })';
        $this->getView()->registerJs($js, View::POS_END);
    }
}